package com.taoyibao.hongcanting.ui.home.views;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.BaseRelativeLayout;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;
import com.taoyibao.hongcanting.widget.HorizontalLineTextView;

/**
 * @author TangAnna
 * @description: 点单页面上半部分的餐厅推荐Item
 * @date :${DATA} 16:52
 */
public class ItemMenuRecommendArea extends BaseRelativeLayout<DishModel> {

    /**
     * 菜品名称
     */
    private TextView mTvName;
    /**
     * 食材
     */
    private TextView mTvDishFrom;
    /**
     * 优惠价格
     */
    private TextView mTvDiscountPrice;
    /**
     * 原价
     */
    private HorizontalLineTextView mTvPrice;

    /**
     * 菜品图片
     */
    private ImageView mIvPic;
    private CountControllerArea mCountControllerArea;

    public ItemMenuRecommendArea(Context context) {
        super(context);
    }

    public ItemMenuRecommendArea(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemMenuRecommendArea(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        mTvName = findViewById(R.id.tv_dish_name);
        mTvDishFrom = findViewById(R.id.tv_dish_form);
        mTvDiscountPrice = findViewById(R.id.tv_dish_discount_price);
        mTvPrice = findViewById(R.id.tv_dish_price);
        mIvPic = findViewById(R.id.iv_dish_pic);
        mCountControllerArea = findViewById(R.id.count_controller);
        mCountControllerArea.setSource(CodeConstant.EVENT_SOURCE_MENU);
    }

    @Override
    public void setData(DishModel data) {
        //名称
        if (!TextUtils.isEmpty(data.dish_name)) {
            mTvName.setText(data.dish_name);
        }
        //食材
        if (!TextUtils.isEmpty(data.dish_form)) {
            mTvDishFrom.setText(data.dish_form);
        }
        //原价
        mTvPrice.setData(CodeUtils.formatAmountUnit(data.dish_price) + "/" + data.dish_unit);
        //优惠价
        mTvDiscountPrice.setText(CodeUtils.formatAmountUnit(data.dish_discount_price) + "/" + data.dish_unit);
        //图片
        GlideUtil.getInstance().loadDefaultImage(getContext(), data.dish_pic, mIvPic);
        //数量
        mCountControllerArea.setData(data);
        //食材
        mTvDishFrom.setText("食材:" + data.dish_form);
    }

    /**
     * 更新数量
     *
     * @param dishModel
     */
    public void updataCount(DishModel dishModel) {
        mCountControllerArea.setData(dishModel);
    }

    @Override
    protected int bindLayout() {
        return R.layout.item_menu_recommend;
    }
}
